package com.liusy.serachengine.parserFile;


import java.io.FileInputStream;
import java.io.InputStream;

import javax.mail.Session;
import javax.mail.internet.MimeMessage;

import org.apache.log4j.Logger;

import com.liusy.serachengine.mail.ResolveEml;


public class ParserEml {
	private static Logger log = Logger.getLogger(ParserEml.class);
	private static StringBuffer content = new StringBuffer("");

	public static StringBuffer readEmlFile(String path) {
		try {
		   InputStream is = new FileInputStream(path);
		   Session mailSession = Session.getDefaultInstance(System.getProperties(), null);
		   MimeMessage mm = new MimeMessage(mailSession, is);
		   ResolveEml pmm = null;
		   pmm = new ResolveEml((MimeMessage) mm);
		   content.append("发件人："+pmm.getFrom()+"<BR>");
		   content.append("接收人："+pmm.getMailAddress("to")+"<BR>");
		   content.append("抄送人："+pmm.getMailAddress("cc")+"<BR>");
		   content.append("发送日期："+pmm.getSentDate()+"<BR>");
		   content.append("主题："+pmm.getSubject()+"<BR>");
		   content.append("发送者："+  pmm.getSender()+"<BR>");
		   content.append("内容："+ParserHtml.removeHtmlTag(pmm.getBodyText())+"<BR>");
		} 
		catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return new StringBuffer(content.toString());
	}


}
